package com.translate.web.service.impl;

import com.comm.util.contract.IFunction;
import com.translate.web.dao.ProductCategoryMapper;
import com.translate.entity.ProductCategory;
import com.param.contract.IPage;
import com.translate.web.service.IProductCategoryService;
import com.basic.service.impl.BaseServiceImpl;
import com.translate.vo.contract.IProductVO;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

import org.springframework.stereotype.Service;

@Service
public class ProductCategoryServiceImpl extends BaseServiceImpl<ProductCategory> implements IProductCategoryService {
	public ProductCategoryServiceImpl(ProductCategoryMapper mapper) {
		super(mapper);
	}

	protected Class<ProductCategory> getEntityClass() {
		return ProductCategory.class;
	}
	
	protected <S extends IPage> String sqlByGetPageListAfterProcesser(S param) {
		return this.sqlByGetPageList(" status = 1");
	}
	
	protected <S extends IPage> String sqlByGetCounttAfterProcesser(S param) {
		return this.sqlByGetCount(" status = 1");
	}
	
	protected Function<ProductCategory, Integer> getFunctionByForListConvertMap() {
		
		return ProductCategory::getId;
	}
	
	@Override
	public <VO> List<VO> getDataByIdsMergeVO(List<VO> list, Function<VO, Integer> function) {

		
		return this.getDataByIdsMergeVO(list, function, new String[] {"id", "name"}, new IFunction<VO, VO>() {

			@Override
			public <K, V> VO apply(VO t, V map) {
				
				IProductVO productVO = (IProductVO)t;
				
				ProductCategory category = (ProductCategory) map;
				
				productVO.setCategoryName(category.getName());
				
				return t;
			}
		});
	}
	
	/**
	 * 
	 */
	protected String getAssocKey() {
		return "id";
	}


}